#include "Socket.h"
#include "Foundation.h"



CSocket::CSocket()
{
    m_nSocket_fd = SOCKET_NULL;
    memset((void *)&m_addrHost, 0, sizeof(m_addrHost));
}


CSocket::~CSocket()
{
    SOCKET_CLOSE(m_nSocket_fd);
}


std::string CSocket::GetHost()
{
    return CFoundation::LongToIPv4(m_addrHost.sin_addr.s_addr);
}


int CSocket::GetPort()
{
    if(CFoundation::CheckEndian())
    {// Big endian
        return m_addrHost.sin_port;
    }
    else
    {// Little endian
        return ((m_addrHost.sin_port & 0xff00) >> 8) | ((m_addrHost.sin_port & 0x00ff) << 8);
    }
}


CSocket::operator SOCKET()
{
    return m_nSocket_fd;
}